﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Diagnostics;
using Infrastructure.Diagnostics;

namespace TempEmployees.BLL.Diagnostics
{
    public static class TraceLogger
    {
        private static readonly string ENTRY_PATTERN =
            "Severity: {0} | Date: {1} | Caller: {2} | SessionID: {3} | Message: {4}";

        static TraceLogger()
        {
            Logger.Log += new EventHandler<LoggerEventArgs>(LoggerEventHandler);
        }

        private static void LoggerEventHandler(object sender, LoggerEventArgs e)
        {
            string entry = string.Format(ENTRY_PATTERN, e.Severity.ToString(), e.Date.ToString(), e.Caller, e.SessionID, e.Message);
            switch (e.Severity)
            {
                case Severity.Debug:
                case Severity.Info:
                    Trace.WriteLine(entry);
                    break;
                case Severity.Error:
                    Trace.TraceError(entry);
                    break;
            }
        }

        public static void Start() { }
    }
}